<template>
  <div id="questionChart"
       ref="questionChart" style="height: 300px;margin-top: 1px">
  </div>
</template>
<script>
import * as echarts from 'echarts/core';
import {GridComponent} from 'echarts/components';
import {LineChart} from 'echarts/charts';
import {UniversalTransition} from 'echarts/features';
import {CanvasRenderer} from 'echarts/renderers';
import {analyse} from "@/api/questionnaire";

echarts.use([GridComponent, LineChart, CanvasRenderer, UniversalTransition]);

export default {
  name: "QuestionChart",
  props: {
    id: {
      type:Number
    },
    data:{

    }
  },
  data(){
    return{
      analysis:null,
    }
  },
  methods: {
    init() {
      let option = {
        tooltip: {
          trigger: 'item'
        },
        grid:{
          width:"500px"
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: '选项',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              // { value: 108, name: 'Search Engine' },
            ]
          }
        ]
      };
      for(let i=0;i<this.data.length;i++){
        option.series[0].data.push({value: this.data[i].value,name: this.data[i].name})
      }
      const questionChart = echarts.init(this.$refs.questionChart)
      questionChart.setOption(option);
/*      analyse({id:this.id})
        .then((response) => {
          if (response.success) {
            this.analysis=response.data
            let i=0;
            for(;i<this.analysis.length;i++){
              option.series[0].data.push({value: this.analysis[i].value,name: this.analysis[i].name})
            }
            const questionChart = echarts.init(this.$refs.questionChart)
            questionChart.setOption(option);
          }
        })
        .catch((e) => {
          _this.$message.error(e, "出现未知错误");
        });*/

      // option && myChart.setOption(option);
    }
  },
  mounted() {
    this.init()
  },
}
</script>
